package com.vhall.component.service.account.impl;

import com.vhall.component.entity.room.dto.RoomsEntityDTO;
import com.vhall.component.entity.room.enums.LiveWatchLimitCheckEnum;
import com.vhall.component.entity.room.enums.LiveWatchLimitOperateEnum;
import com.vhall.component.entity.room.vo.LiveWatchCheckRequestVO;
import com.vhall.component.entity.room.vo.LiveWatchCheckResponseVO;
import com.vhall.component.framework.common.exception.BusinessException;
import com.vhall.component.plugin.common.exception.BizErrorCode;
import com.vhall.component.service.account.LiveWatchCheck;
import com.vhall.component.service.room.RoomInnerService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * SecuritiesResearchLiveWatchCheck-
 * 证券研究类直播的检查校验
 * @author xing.wang
 * @date 2023/8/19
 */
@Component
public class SecuritiesResearchLiveWatchCheck extends CommonLiveWatchCheck implements LiveWatchCheck {
    @Resource
    private RoomInnerService roomInnerService;

    @Override
    public LiveWatchCheckResponseVO liveWatchCheck(LiveWatchCheckRequestVO vo) {
        LiveWatchCheckResponseVO result = new LiveWatchCheckResponseVO();
        if (checkUserFundAccountBindAndTransactionLogin()) {
            RoomsEntityDTO roomInfoById = Optional.ofNullable(roomInnerService.getRoomInfoById(vo.getIlId())).orElseThrow(()->new BusinessException(BizErrorCode.EMPTY_ROOM));
            result = checkUserRiskMatch(vo, roomInfoById);
        }else{
            result.setCheckResult(LiveWatchLimitCheckEnum.CHECK_FAIL.getValue());
            result.setType(LiveWatchLimitOperateEnum.OPERATE_B.getValue());
        }
        return result;
    }
}
